package com.it.labservice.repository;

import com.it.labservice.entity.SafetyCheck;
import com.it.labservice.entity.User;
import com.it.labservice.entity.Laboratory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public interface SafetyCheckRepository extends JpaRepository<SafetyCheck, Long> {
    
    @Query("SELECT s FROM SafetyCheck s WHERE s.checkDate = :date")
    List<SafetyCheck> findByCheckDate(@Param("date") LocalDate date);
    
    @Query("SELECT s FROM SafetyCheck s WHERE s.checkDate BETWEEN :startDate AND :endDate")
    List<SafetyCheck> findByCheckDateBetween(@Param("startDate") LocalDate startDate, 
                                           @Param("endDate") LocalDate endDate);
    
    List<SafetyCheck> findByUser(User user);
    
    @Query("SELECT s FROM SafetyCheck s WHERE s.user = :user AND s.laboratory = :laboratory AND s.checkDate = :date")
    List<SafetyCheck> findByUserAndLaboratoryAndCheckDate(@Param("user") User user, 
                                                         @Param("laboratory") Laboratory laboratory,
                                                         @Param("date") LocalDate date);
} 